function [ ama ] = getama2( p,a )

if a>1
    a = 2./(a+1);
end
a = a(:);

% ama = zeros(size(p));
% for i = 1:length(p)
%     ama(i) = sum(exp(sum(log(1-a(1:i)))-cumsum(log(1-a(1:i)))) .* a(1:i) .* p(1:i));
% end

ama = zeros(size(p));
ama(1) = p(1);
for i = 2:length(p)
    ama(i) = a(i)*p(i) + (1-a(i)) * ama(i-1);
end

end

